//
//  NSTreeController_Extension.h
//  bcDiscriminator
//
//  Created by Volker Runkel on 03.11.06.
//  Copyright 2006 Volker Runkel, ecoObs.
//	Mail me at runkel @ eco obs . de
//
/*
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#import <Cocoa/Cocoa.h>


@interface NSIndexPath (SomeExtensions)

// get us the final piece of the index path, i.e, the one that tells
// us were this path fits among its siblings

- (unsigned int)lastIndex;

	// answer whether receiver is the ancestor (other is a descendant)

- (BOOL)isAncestorOfIndexPath:(NSIndexPath *)other;

	// answer whether receiver has same immediate parent as other

- (BOOL)isSiblingOfIndexPath:(NSIndexPath *)other;

	// find a common ancestor in the tree controller
	// return nil if no common ancestor
	// these may not be necessary

- (NSIndexPath *)firstCommonAncestorWithIndexPath:(NSIndexPath *)other;
+ (NSIndexPath *)firstCommonAncestorAmongIndexPaths:(NSArray *)otherPaths;

@end

@interface NSTreeController (SomeExtensions)

// convert between NSIndexPaths and managed objects observed by the controller
// used internally, but might be useful if we use the "find common ancestor"
// capability

- (id)objectAtArrangedIndexPath:(NSIndexPath *)path;
- (NSIndexPath *)arrangedIndexPathForObject:(id)object;
- (NSIndexPath *)arrangedIndexPathForObject:(id)object startingAt:(NSIndexPath *)parent;
- (NSArray *)siblingsAtArrangedIndexPath:(NSIndexPath *)path;

	// convert between NSOutlineView items and managed objects observed by the controller

+ (id)objectForOutlineItem:(id)item;
+ (NSArray *)objectsForOutlineItems:(NSArray *)items;

- (id)outlineItemForObject:(id)object;
- (NSArray *)outlineItemsForObjects:(NSArray *)objects;

	// convert between NSOutlineView items and NSIndexPaths

- (id)outlineItemForArrangedIndexPath:(NSIndexPath *)path;
- (NSArray *)outlineItemsForArrangedIndexPaths:(NSArray *)paths;

+ (NSIndexPath *)arrangedIndexPathForOutlineItem:(id)item;

	// recursively find all descendants of an outline item (return outline items
	// which can be converted to objects with objectsForOutlineItems:

- (NSArray *)childOutlineItemsByDepthFirstSearchUnderItem:(id)item;

@end
